var Touch = {
	isTouch:false,
	isFrozen:false,
	init:function(){
		document.addEventListener("touchstart", Touch.handler, true);
		document.addEventListener("touchmove", Touch.handler, true);
		document.addEventListener("touchend", Touch.handler, true);
		document.addEventListener("touchcancel", Touch.handler, true);
	},
	handler:function(event){
		var touch = event.changedTouches[0];
	    var simulatedEvent = document.createEvent("MouseEvent");
	        simulatedEvent.initMouseEvent({
	        touchstart: "mousedown",
	        touchmove: "mousemove",
	        touchend: "mouseup"
	    }[event.type], true, true, window, 1,
	        touch.screenX, touch.screenY,
	        touch.clientX, touch.clientY, false,
	        false, false, false, 0, null);
	
	    touch.target.dispatchEvent(simulatedEvent);
	    //event.preventDefault();
	    Touch.isTouch = true;
	    if(Touch.isFrozen){
	    	event.preventDefault();
	    }
	},
	freeze:function(){ // prevents scrolling
		if(Touch.isTouch){
			var $body = $('body');
			Touch.isFrozen = true;
		}
	},
	unfreeze:function(){
		if(Touch.isFrozen){
			var $body = $('body');
		}
		Touch.isFrozen = false;
	}
};
$(document).ready(function(){
	Touch.init();
	Touch.isTouch = isMobile.any();
});

var isMobile = { 
	Android: function() { return navigator.userAgent.match(/Android/i) != null; }, 
	BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i) != null; }, 
	iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i) != null; }, 
	Opera: function() { return navigator.userAgent.match(/Opera Mini/i) != null; }, 
	Windows: function() { return navigator.userAgent.match(/IEMobile/i) != null; }, 
	any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } 
};